package jdbc;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;

public class JDBCDemo8 {
    public static void main(String[] args) {
        try (Connection connection = DBUtil.getConnection()){
            UserInfo userInfo = InputUtil.getInputObject(new UserInfo(),"注册用户", "注册");
            String sql = "INSERT INTO userinfo(username,password,nickname,age) " +
                         "VALUES(?,?,?,?)";
            PreparedStatement ps = connection.prepareStatement(sql);
            ps.setString(1,userInfo.getUsername());
            ps.setString(2,userInfo.getPassword());
            ps.setString(3,userInfo.getNickname());
            ps.setInt(4,userInfo.getAge());
            System.out.println(ps.executeUpdate()>0?"注册成功":"注册失败");
        } catch (SQLException e) {
            throw new RuntimeException(e);
        }
    }
}
